-module(signalpoint_sup).
-include("network.hrl").
-behaviour(supervisor).
-export([init/1]).
-export([start_link/0,start_child/1,msg_fresh/3,get_sgs/1]).
-define(SERVER,?MODULE).

start_link() ->
	supervisor:start_link({local,?SERVER},?MODULE,[]).
init([]) ->
	Children = [
		{signalpoint,{signalpoint,start_link,[]},temporary,brutal_kill,worker,[signalpoint]}
		],
	RestartStrategy = {simple_one_for_one,0,1},
	{ok,{RestartStrategy,Children}}.
start_child(Params) ->
	supervisor:start_child(?SERVER,Params).

msg_fresh(Addr,Role,Dir) ->
  gen_server:call(net_elem_dis,{Addr,{msg,{Role,Dir}}}).

get_sgs([]) ->
  lists:map(fun({_,Pid,_,_}) ->
              gen_server:call(Pid,get)
            end,
            supervisor:which_children(?SERVER));
get_sgs([NE_Type]) ->
  lists:filter(fun(T) ->
                  check_sg(T,NE_Type)
               end,
               get_sgs([]));
get_sgs(_) ->
  [].
check_sg(T,NE_Type) when T#sp_state.type =:= NE_Type ->
  true;
check_sg(T,NE_Type) ->
  false.
